/**
 * API 路由集合页
 * @authors 杨兴洲（of2502）
 * @date    2017/3/14 18:12
 * @version 1.0
 */
import {Router} from "express";
import authorizerRoutes from "./authorizer";
import authorizationRoutes from "./authorization";
import wxMenuRoutes from "./menu";
import wxMaterialRoutes from "./material";
import wxReplyRoutes from "./reply";
import wxMassRoutes from "./mass";
import wxUserRoutes from "./user";
import wxTagRoutes from "./tag";
import wxStatisticRoutes from "./statistic";
import messageRouters from "./message";
import advancedNewsRoutes from './advancedNews';
import logger from "../../util/logger";

const router = Router();
router.use('/authorization', authorizationRoutes);
router.use('/authorizer', authorizerRoutes);
router.use('/menu', wxMenuRoutes);
router.use('/material', wxMaterialRoutes);
router.use('/message/mass', wxMassRoutes);
router.use('/message/reply', wxReplyRoutes);
router.use('/message/msg', messageRouters);
router.use('/user', wxUserRoutes);
router.use('/tag', wxTagRoutes);
router.use('/statistic', wxStatisticRoutes);
router.use('/advancedNews', advancedNewsRoutes);

// api接口不报错,输出json
router.use((err, req, res, next) => {
    logger.error("请求方法:", req.method, req.originalUrl);
    logger.error("请求参数:", req.method === "POST" ? req.body : req.query);
    logger.error("错误信息:", err);
    res.json(err);
});
export default router;
